﻿using System;
using WindowsGame.Data;
using WindowsGame.Enums;
using WindowsGame.Manager;
using WindowsGame.Static;
using WindowsGame.Library.Data;
using WindowsGame.Library.IoC;
using WindowsGame.Tests.Data;
using NUnit.Framework;

namespace WindowsGame.Tests
{
	[TestFixture]
	public class DataManagerTests
	{
		// System under test.
		private IDataManager dataManager;

		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			IoCContainer.Initialize<IDataManager, DataManager>();

			IoCContainer.Initialize<IFileProxy, TestFileProxy>();
			IoCContainer.Initialize<IFileManager, FileManager>();
		}

		[SetUp]
		public void SetUp()
		{
			dataManager = IoCContainer.Resolve<IDataManager>();
		}

		[Test]
		public void AllDataTest()
		{
			String boardFile = GetPath("BoardData.txt");
			String snakeFile = GetPath("SnakeData.xml");

			String[] files = new[] { boardFile, snakeFile };
			AllData data = dataManager.LoadData(files);

			Assert.AreEqual(GameSize.Small, data.GameSize);
			Assert.AreEqual(8, data.SnakeData.Length);
			
		}

		private static String GetPath(String name)
		{
			return GetPath(Constants.DATA_DIRECTORY, name);
		}
		private static String GetPath(String fldr, String name)
		{
			String root = @"..\..\..\..\WindowsGame\WindowsGame\bin\x86\Debug\";
			String path = String.Format("{0}/{1}/{2}", Constants.ROOT_DIRECTORY, fldr, name);

			return String.Format("{0}{1}", root, path);
		}

		[TestFixtureTearDown]
		public void TestFixtureTearDown()
		{
			IoCContainer.Release();
		}
	}
}